package lesfiersarepasser.assoc.servlet;

import java.io.IOException;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import lesfiersarepasser.assoc.bdd.DerbyConnection;

/**
 * Servlet implementation class Order
 */
public class Order extends HttpServlet {
	private static final long serialVersionUID = 1L;

	/**
	 * @see HttpServlet#HttpServlet()
	 */
	public Order() {
		super();
		// TODO Auto-generated constructor stub
	}

	/**
	 * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse
	 *      response)
	 */
	protected void doGet(HttpServletRequest request,
			HttpServletResponse response) throws ServletException, IOException {
		// TODO Auto-generated method stub
		getServletContext().getRequestDispatcher("/jsp/Template.jsp?page=Articles").forward(request, response);
	}

	/**
	 * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse
	 *      response)
	 */
	protected void doPost(HttpServletRequest request,
			HttpServletResponse response) throws ServletException, IOException {
		process(request, response);
		getServletContext().getRequestDispatcher("/jsp/Template.jsp?page=Articles").forward(request, response);
	}

	private void process(HttpServletRequest request,
			HttpServletResponse response) {
		DerbyConnection.addArticleOrder(request.getSession().getAttribute("login").toString(),
				request.getParameter("article"),
				Integer.parseInt(request.getParameter("articleQuantity")));
	}

}
